varying vec2 texCoord;

uniform sampler2D m_Grass;
uniform sampler2D m_Dirt;
uniform sampler2D m_AlphaMap;
uniform float m_ScaleWidth;
uniform float m_ScaleHeight;

void main(){
	vec2 scaledCoord = vec2(texCoord.x * (m_ScaleWidth + 20), texCoord.y * (m_ScaleHeight + 20));
	float xOffset = texCoord.x * (m_ScaleWidth + 20) / m_ScaleWidth - 10 / m_ScaleWidth;
	float yOffset = texCoord.y * (m_ScaleHeight + 20) / m_ScaleHeight - 10 / m_ScaleHeight;
	vec4 grassColor = texture2D(m_Grass, scaledCoord);
	vec4 dirtColor = texture2D(m_Dirt, scaledCoord);
	vec4 alphaColor = texture2D(m_AlphaMap, vec2(xOffset, yOffset));
	
	gl_FragColor = mix(grassColor, dirtColor, alphaColor.a);
}